package com.kayak.kboot.dao.kSql.object;

import java.util.ArrayList;
import java.util.List;

/**
 * 通用SQL配置模型
 */
public class SqlConfig
{
	class Sql{
		String sql;
		String dialect;
		public String getSql() {
			return sql;
		}
		public void setSql(String sql) {
			this.sql = sql;
		}
		public String getDialect() {
			return dialect;
		}
		public void setDialect(String dialect) {
			this.dialect = dialect;
		}
	}
	private List<Sql> sqls = new ArrayList<Sql>();
	private String sqlid;
	private String sqlname;
//	private String sql;
	private List<SqlCheck> checks;
	private List<SqlTransfer> transfers;
	private SqlQueryTree qureytree;
//	private String dialect;

	public SqlConfig(String sqlid, String sqlname,List<SqlCheck> checks,
			List<SqlTransfer> transfers, SqlQueryTree qureytree)
	{
		this.sqlid = sqlid;
		this.sqlname = sqlname;
		
		this.checks = checks;
		this.transfers = transfers;
		this.qureytree = qureytree;
		
	}

	
	public List<Sql> getSqls() {
		return sqls;
	}

	public void setSqls(List<Sql> sqls) {
		this.sqls = sqls;
	}

	public String getSqlid()
	{
		return sqlid;
	}

	public void setSqlid(String sqlid)
	{
		this.sqlid = sqlid;
	}

	public String getSqlname()
	{
		return sqlname;
	}

	public void setSqlname(String sqlname)
	{
		this.sqlname = sqlname;
	}

//	public String getSql()
//	{
//		return sql;
//	}

	
	public List<SqlCheck> getChecks()
	{
		return checks;
	}

	public void setChecks(List<SqlCheck> checks)
	{
		this.checks = checks;
	}

	public List<SqlTransfer> getTransfers()
	{
		return transfers;
	}

	public void setTransfers(List<SqlTransfer> transfers)
	{
		this.transfers = transfers;
	}

	public SqlQueryTree getQureytree()
	{
		return qureytree;
	}

	public void setQureytree(SqlQueryTree qureytree)
	{
		this.qureytree = qureytree;
	}
	
	public String getSql(){
		if(sqls == null && sqls.size() < 1){
			return "";
		}
		for(Sql s:sqls){
			return s.getSql();
		}
		return sqls.get(0).getSql();
		
	}

	public String getSql(String dbType){
		if(dbType == null || dbType.equals("")){
			return this.getSql();
		}
		for(Sql s:sqls){
			if(dbType.trim().equalsIgnoreCase(s.getDialect().trim()) && s.getDialect() != null){
				return s.getSql();
			}
		}
		return sqls.get(0).getSql();
	}	
	

	public void addSql(String sql,String dialect){
		Sql s = new Sql();
		s.setSql(sql);
		s.setDialect(dialect);
		sqls.add(s);
	}
}
